Run 'read-only-mode-hook' when visiting a file that is not writable
authorEli Zaretskii <eliz@gnu.org>
Sat, 10 Feb 2024 08:35:18 +0000 (10:35 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 10 Feb 2024 08:35:18 +0000 (10:35 +0200)
* lisp/files.el (after-find-file): Run 'read-only-mode-hook'
when the visited file is not writable.  (Bug#68648)

lisp/files.el

index 229771810fb4f91a056bb11d6f58f7939c2c1eec..f67b650cb924bda623e87d5adefafdb0c85e0d6f 100644 (file)
@@ -2747,6 +2747,10 @@ Fifth arg NOMODES non-nil means don't alter the file's modes.
 Finishes by calling the functions in `find-file-hook'
 unless NOMODES is non-nil."
   (setq buffer-read-only (not (file-writable-p buffer-file-name)))
+  ;; The above is sufficiently like turning on read-only-mode, so run
+  ;; the mode hook here by hand.
+  (if buffer-read-only
+      (run-hooks 'read-only-mode-hook))
   (if noninteractive
       nil
     (let* (not-serious